import { createRouter, createWebHistory } from 'vue-router' // Vue 3 的导入方式

const routes = [
  {
    path: '/',
    name: 'HomeView',
    component: () => import('../views/HomeView.vue')
  },
  {
    path: '/adm',
    name: 'adm',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import(/* webpackChunkName: "about" */ '../views/AdminView.vue')
  },
  {
    path: '/userRegister',
    name: 'userRegister',
    component: () => import('../views/userRegister.vue')
  },
  {
    path: '/sellerRegister',
    name: 'sellerRegister',
    component: () => import('../views/sellerRegister.vue')
  },
  {
    path: '/userView',
    name: 'userView',
    component: () => import('../views/userView.vue'),
    meta: { requiresAuth: true, role: 'user' } // 需要管理员权限
  },
  {
    path: '/userLogin',
    name: 'userLogin',
    component: () => import('../views/userLogin.vue')
  },
  {
    path: '/adminLogin',
    name: 'adminLogin',
    component: () => import('../views/AdminLogin.vue'),
    meta: { requiresAuth: true, role: 'admin' } // 需要管理员权限
  },
  {
    path: '/AdminView',
    name: 'AdminView',
    component: () => import('../views/AdminView.vue'),
    meta: { requiresAuth: true, role: 'admin' } // 需要管理员权限
  },
  {
    path: '/sellerLogin',
    name: 'sellerLogin',
    component: () => import('../views/sellerLogin.vue')
  },
  {
    path: '/sellerView',
    name: 'sellerView',
    component: () => import('../views/sellerView.vue'),
    meta: { requiresAuth: true, role: 'seller' } // 需要管理员权限
  },
  {
    path:'/shoppingCart',
    name:'shoppingCart',
    component:() =>import('../views/shoppingCart.vue')
  },
  {
    path: '/sellerDashboard',
    name: 'sellerDashboard',
    component: () => import('@/views/SellerDashboard.vue'),
    meta: { requiresAuth: true, role: 'seller' } // 需要商家权限
  },
  {
    path: '/userProfile',
    name: 'userProfile',
    component: () => import('../views/userProfile.vue'),
    meta: { requiresAuth: true, role: 'user' } // 需要用户权限
  },
  {
    path: '/userOrders',
    name: 'userOrders',
    component: () => import('../views/UserOrdersView.vue'),
    meta: { requiresAuth: true, role: 'user' } // 需要用户权限
  }
]

const router = createRouter({
  history: createWebHistory(), // 使用 HTML5 History 模式
  routes
})

export default router
